package muilty_thread.pic_java_design_pattern.GuardedSuspension;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @version: 1.0
 * @Description: TODO
 * @author: zZmH
 * @date: 2020/10/12 00:21
 */


public class RequestQueue {
    private final Queue<Request> queue = new LinkedList<>();

    public synchronized Request getRequest() throws InterruptedException {
        while (queue.isEmpty()) {
            wait();
        }

        return queue.poll();
    }

    public synchronized void putRequest(Request request) {
        queue.offer(request);
        notifyAll();

    }
}
